package com.yc.d0415;

public class 创建线程 {

    public static void main(String[] args) {

        long time1 = System.currentTimeMillis();

        MyThread myThread = new MyThread();
        // 启动线程
        myThread.start();

        Thread t = new Thread(new B());
        t.start();

        // 匿名类
        Thread t1 = new Thread() {
            @Override
            public void run() {
                System.out.println("擦黑板");
            }
        };

        // lambda 表达式
        Thread t2 = new Thread(() -> {
            System.out.println("摆桌子");
        }
        );

        t1.start();
        t2.start();


//        saodi();
//        cachuang();
        long time2 = System.currentTimeMillis();
        System.out.println(time2 - time1);

    }

    public static void saodi() {
        System.out.println("扫地");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void cachuang() {
        System.out.println("擦窗");
        // 让当前线程进入到休眠状态, 单位毫秒
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

// 继承Thread方式
class MyThread extends Thread {
    @Override
    public void run() {
        创建线程.saodi();
    }
}

class A {

}

// 实现接口方式
class B extends A implements Runnable {
    @Override
    public void run() {
        创建线程.cachuang();
    }
}